document.write('<script type="text/javascript" src="' + context
		+ '/resources/common/js/windowopen.js"></script>');

/**
 * 过滤掉非监理人员节点
 * 
 * @param {}
 *            node
 * @return {}
 */
function selfShowNodeDecide(node) {
	// alert(node.text + '<--->' + node.attributes.type + '<--->' +
	// node.attributes.rating);
	var rnt = true;

	if (node.attributes.type == 'user'
			&& (node.attributes.rating != 1 && node.attributes.rating != 2)) {
		rnt = false;
	}
	return rnt;
}

/**
 * 重构信息列表初始化后回调函数
 */
function callBackAfterList() {

}

/**
 * 查看考勤照片
 * 
 * @param {}
 *            id
 * @param {}
 *            name
 * @param {}
 *            ktime
 */
function viewImg(id, name, ktime) {
	/*
	 * var str = '<img src="' + $(id).getAttribute('url') + '" width="100%"
	 * height="100%">';
	 * 
	 * var win = new Ext.Window({ renderTo : Ext.getBody(), layout : 'fit',
	 * width : 500, height : 400, title : name, resizable : true, maximizable :
	 * true, plain : true, modal : true, html : str,
	 * 
	 * buttons : [{ text : '下 载', handler : function() { viewAnnex(id); } }, {
	 * text : '关 闭', handler : function() { win.close(); } }] });
	 * 
	 * win.show(this);
	 */

	var title = name + ' ' + ktime + ' 考勤照片';

	var url = context + '/system/annex/annexview.jsp?id=' + id + '&name='
			+ title + '&type=jpg&url=' + $(id).getAttribute('url');

	popwindow(url, '', 700, 500);
}

function getMapView(klon, klat, kusername, ktype, ktime, kpath) {
	var title = kusername + ' ' + ktime + ' 考勤位置';

	var url = context + '/app/kaoqin/loadmap.jsp?klon=' + klon + '&klat='
			+ klat + '&kusername=' + kusername + '&ktype=' + ktype + '&ktime='
			+ ktime + '&kpath=' + kpath;

	popwindow(url, '', 800, 600);
}

/**
 * 个人轨迹查询
 * @param {} userId
 * @param {} userName
 * @param {} ktime
 */
function getTrackView(userId, userName, ktime) {
	var url = context + '/app/maps/usertrackmap.jsp?userId=' + userId
			+ '&userName=' + Ext.encode(userName) + '&ktime=' + ktime;	
	popwindow(url, '', 900, 600);
}

/**
 * 重构信息列赋值函数
 */
function renderTQJspListHeader(value, cellmeta, record, rowIndex, columnIndex,
		store) {
	var fieldName = cellmeta.getDataIndex(columnIndex);
	if (fieldName == 'K_ZHAOPIAN') {

		if (value != null && value.length > 0) {
			var name = record.data['K_USERNAME'];
			var ktime = formatTime(record.data['K_CTIME']);
			return getItemPic(value[0], name, ktime);
		}

	} else if (fieldName == 'K_TYPE') {
		if (value == 0) {
			return '签到';
		}
		if (value == 1) {
			return '签退';
		}
	} else if (fieldName == 'K_USERNAME') {
		return '<div class="divn"  title="' + value + '">' + value + '</div>';
	} else if (fieldName == 'K_GROUPNAME') {
		return '<div class="divn"  title="' + value + '">' + value + '</div>';
	} else if (fieldName == 'K_CTIME') {
		return formatTime(value);
	} else if (fieldName == 'K_LON') {
		var lon = record.data['K_LON'];
		if (lon.length > 15) {
			return '基站定位';
		} else {
			return 'GPS定位';
		}
	} else if (fieldName == 'SP') {
		var klon = record.data['K_LON'];
		var klat = record.data['K_LAT'];
		var kusername = record.data['K_USERNAME'];
		var ktype = record.data['K_TYPE'];
		var ktime = formatTime(record.data['K_CTIME']);

		var pic = record.data['K_ZHAOPIAN'];
		var kpath = '';
		if (pic != null && pic.length > 0) {
			kpath = getItemPicPath(pic[0]);
		}

		return '<a href="javascript:getMapView(' + klon + ',' + klat + ',\''
				+ kusername + '\',' + ktype + ',\'' + ktime + '\',\'' + kpath
				+ '\')">考勤位置</a><br/>' + '<a href="javascript:getTrackView(\''
				+ record.data['K_USERID'] + '\',\'' + kusername + '\',\''
				+ record.data['K_CTIME'] + '\')">查看轨迹</a>';
	}
	return value;
}

/**
 * 考勤预览图片
 * 
 * @param {}
 *            item
 * @param {}
 *            name
 * @param {}
 *            ktime
 * @return {}
 */
function getItemPic(item, name, ktime) {
	var id = item.id;
	var str = '';
	var type = item.type;
	if (type == 'jpg') {
		var url = context + '/temp-store/' + item.folder + '/' + id + '.data';

		str += '<div class="divn" style="width:70px;" title="查看详细" onClick="javascript:viewImg(\''
				+ id
				+ '\', \''
				+ name
				+ '\', \''
				+ ktime
				+ '\');">'
				+ '<img item="img" url="'
				+ item.url
				+ '" id="'
				+ id
				+ '" style="cursor:hand;" width="64" height="64" src="'
				+ url
				+ '"/></div>'
	} else {
		str += '<div class="divn" style="width:70px;" title="下载文件" onclick="javascript:viewAnnex(\''
				+ id
				+ '\');">'
				+ '<img style="cursor:hand;" width="64" height="64" src="'
				+ context + '/app/file/images/file.png"/></div>'
	}
	return str;
}

function getItemPicPath(item) {
	var id = item.id;
	var url = context + '/temp-store/' + item.folder + '/' + id + '.data'
	return url;
}
